package com.jhd.fuzhou.view.task;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;

import com.alibaba.fastjson.JSON;
import com.jhd.fuzhou.view.login.BaseActivity;
import com.jhd.fuzhou.R;
import com.jhd.fuzhou.util.CustomToast;
import com.jhd.fuzhou.vo.PersonInfoVo;
import com.jhd.fuzhou.vo.SupervisionInspectionVo;

import net.zigin.commons.util.StringUtil;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jhd.fuzhou.util.StartProcess.completeByAssign2;

/*撤销审核*/
public class CancelAuditActivity extends BaseActivity {
    @BindView(R.id.et_reason)EditText et_reason;
    private Context context=this;
    private SupervisionInspectionVo supervisionInspectionVo;
    private List<PersonInfoVo> personInfoVos;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.activity_cancel_audit);
    }

    @Override
    protected void processLogic() {
        String data = getIntent().getStringExtra("data");
        supervisionInspectionVo= JSON.parseObject(data, SupervisionInspectionVo.class);
        findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onCancel();
            }
        });
    }
    @OnClick({R.id.btn_post,R.id.btn_cancel})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_post:
                Map<String, Object> params = new LinkedHashMap<String, Object>();
                HashMap map = new HashMap();
                map.put("restart", "1");
                if(StringUtil.isNullOrEmpty(et_reason.getText().toString().trim())){
                    CustomToast.showText(context,"请输入驳回原因!",3000,0,0).show();
                }else{
                    completeByAssign2(application, supervisionInspectionVo.getCreateUser(),
                            supervisionInspectionVo.getTaskId(), et_reason.getText().toString(), map, supervisionInspectionVo.getId(), "已驳回","驳回成功！", context);
                }
                break;
            case R.id.btn_cancel:
                onCancel();
                break;
        }
    }
    public void onCancel() {
        Intent intent = new Intent();
        intent.putExtra("position","2");
        ((Activity)context).setResult(RESULT_OK, intent);
        ((Activity)context).finish();
    }
}